
/**
 * Densitometric measurement. Produces time-density curve of a ROI on DSAs.
 */

#define FRAMES_PER_SEC 15
 
#include <fstream>
#include <iostream>
#include <vector>

using namespace std;

#include "dmetry.h"


int main ( int argc, char **argv )
{
	// process command line args
	if ( argc != 4 && argc != 5 )
	{
		cout << "Usage: " << argv[ 0 ]
		<< " input.dsa input.roi output.txt [input.vm]" << endl;
		return -1;
	}
	char *input_dsa_file = argv[ 1 ];
	char *input_roi_file = argv[ 2 ];
	char *output_file = argv[ 3 ];
	char *input_vm_file = NULL;
	if ( argc == 5 )
	{
		input_vm_file = argv[ 4 ];
	}

	vector< double > dcurve;
	if ( input_vm_file == NULL )
	{
		dcurve = dmetry ( input_dsa_file, input_roi_file );
	}
	else
	{
		dcurve = dmetry ( input_dsa_file, input_roi_file, input_vm_file );
	}

	// print output
	ofstream output;
	output.open ( output_file );
	for ( int i = 0; i < dcurve.size(); ++ i )
	{
		output << (double)i / FRAMES_PER_SEC << " " << 255 - dcurve[ i ] << endl;
	}
	output.close();

	return 0;
}

